extends Node2D

signal game_event(event_type,data)
signal res

@onready var dashtime: Label = $Dashtime
var is_dash:String = "是"
var tween = create_tween()
@onready var don: Button = $Don
var button_repeatable_size:int = 10000
var text_button_repeatable:Array[int] = []
var Richtext_button_repeatable:Array[int] = []
var Player_scene = preload("res://Scene/player_2d.tscn")

@onready var control: Control = $UI/Control
@onready var label: Label = $UI/Control/Panel/MarginContainer/Label
@onready var player_2d = get_parent().get_node("Player2D") as CharacterBody2D

#心声字体大小
var font_size

#心声
@onready var mind_00: Area2D = $Mind/Mind00
@onready var mind_01: Area2D = $Mind/Mind01
@onready var mind_02: Area2D = $Mind/Mind02
@onready var mind_03: Area2D = $Mind/Mind03
@onready var mind_04: Area2D = $Mind/Mind04
@onready var mind_05: Area2D = $Mind/Mind05



@onready var 压力板: Area2D = $压力板集合/压力板
@onready var 压力板2: Area2D = $压力板集合/压力板2
@onready var 压力板3: Area2D = $压力板集合/压力板3
@onready var 压力板4: Area2D = $压力板集合/压力板4
@onready var 压力板6: Area2D = $压力板集合/压力板6
@onready var 压力板7: Area2D = $压力板集合/压力板7
@onready var 压力板8: Area2D = $压力板集合/压力板8
@onready var 压力板9: Area2D = $压力板集合/压力板9
@onready var 压力板10: Area2D = $压力板集合/压力板10
@onready var a选项: Area2D = $压力板集合/A选项
@onready var b选项: Area2D = $压力板集合/B选项
@onready var c选项: Area2D = $压力板集合/C选项
@onready var d选项: Area2D = $压力板集合/D选项
@onready var 彩蛋压力板: Area2D = $压力板集合/彩蛋压力板


@onready var text_1: Label = $文本框集合/Text1
@onready var text_2: Label = $文本框集合/Text2
@onready var text_3: Label = $文本框集合/Text3
@onready var text_4: Label = $文本框集合/Text4
@onready var text_5: Label = $文本框集合/Text5

@onready var r_text_1: RichTextLabel = $富文本集合l/RText1
@onready var r_text_2: RichTextLabel = $富文本集合l/RText2
@onready var r_text_3: RichTextLabel = $富文本集合l/RText3
@onready var r_text_4: RichTextLabel = $富文本集合l/RText4
@onready var r_text_5: RichTextLabel = $富文本集合l/RText5


var TextArray:Array[Label]
var RichTextArray:Array[RichTextLabel]
@onready var 出生点: Area2D = get_node("Checkpoints/出生点")
@onready var 出生点位置: CollisionShape2D = get_node("Checkpoints/出生点/出生点")
@onready var checkpoint_1: CollisionShape2D = $Checkpoints/Checkpoint1/Checkpoint1
@onready var checkpoint_2: CollisionShape2D = $Checkpoints/Checkpoint2/Checkpoint2
@onready var checkpoint_3: CollisionShape2D = $Checkpoints/Checkpoint3/Checkpoint3


@onready var 荆棘图: Sprite2D = $阻碍集合/荆棘/荆棘图
@onready var 荆棘图2: Sprite2D = $阻碍集合/荆棘/荆棘图2
@onready var 荆棘图3: Sprite2D = $阻碍集合/荆棘/荆棘图3
@onready var 荆棘图4: Sprite2D = $阻碍集合/荆棘/荆棘图4
@onready var 荆棘图5: Sprite2D = $阻碍集合/荆棘/荆棘图5
@onready var 荆棘碰撞: CollisionShape2D = $阻碍集合/荆棘/荆棘碰撞
@onready var 掉下的书页: Sprite2D = $阻碍集合/掉下的书页/掉下的书页
@onready var 掉下书页的碰撞: CollisionPolygon2D = $阻碍集合/掉下的书页/掉下书页的碰撞
@onready var 落下苦水: Sprite2D = $阻碍集合/落下的苦水/落下苦水
@onready var 落下苦水碰撞: CollisionShape2D = $阻碍集合/落下的苦水/落下苦水碰撞
@onready var 题目遮挡: Sprite2D = $阻碍集合/题目遮挡
@onready var 斜体sprite: Sprite2D = $阻碍集合/斜体/斜体sprite
@onready var 斜体碰撞: CollisionShape2D = $阻碍集合/斜体/斜体碰撞
@onready var 暂时阻挡: StaticBody2D = $阻碍集合/暂时阻挡
@onready var 结束: Sprite2D = $结束



@onready var camera_2d: Camera2D = $Camera2D
@onready var 左边界: StaticBody2D = $空气墙集合/左边界
@onready var 左边界域: CollisionShape2D = $空气墙集合/左边界/左边界域
@onready var 沙比彩蛋: Sprite2D = $沙比彩蛋
@onready var 黑幕: Sprite2D = $黑幕
@onready var 书桌: Sprite2D = $书桌
@onready var 书: Sprite2D = $书
@onready var 书2: Sprite2D = $书2
@onready var 书3: Sprite2D = $书3
@onready var 书4: Sprite2D = $书4
@onready var 白鲸记: Sprite2D = $白鲸记


var 场景转换点0:bool = true
var 场景转换点1:bool = true
var 场景转换点2:bool = true
var 场景转换点3:bool = true
var 场景转换点4:bool = true
var 彩蛋:bool = true

@onready var checkpoints: Node = $Checkpoints

@onready var time_debug: Label = $TimeDebug
var time_order:float = 0
@onready var ship: StaticBody2D = $Ship

func _ready() -> void:
	font_size = label.get_theme_font_size("font_size")
	control.modulate.a = 0
	黑幕.visible = true
	结束.visible = false
	await get_tree().create_timer(1.5).timeout
	var tween_enter:Tween = get_tree().create_tween()
	tween_enter.tween_property(黑幕,"modulate",Color(1.0,1.0,1.0,0.0),1.5)
	camera_2d.global_position = Vector2(-844.0,-1)
	左边界域.global_position = Vector2(-1417,-1.5)

	var State_machine = get_parent().get_node("Player2D/State Machine")
	var windows = get_parent().get_parent()
	res.connect(windows.build_bridge)
	windows.connect("summer_end",_on_show_ending)
	if State_machine:
		game_event.connect(State_machine._on_main_game_event)
	else:
		print("警告：未找到状态机节点")
	var ship_is_shaking = true
	场景转换点1 = true
	text_button_repeatable.resize(button_repeatable_size)
	text_button_repeatable.fill(1)
	Richtext_button_repeatable.resize(button_repeatable_size)
	Richtext_button_repeatable.fill(1)
	
	TextArray.append(text_1)
	TextArray.append(text_2)
	TextArray.append(text_3)
	TextArray.append(text_4)
	TextArray.append(text_5)
	RichTextArray.append(r_text_1)
	RichTextArray.append(r_text_2)
	RichTextArray.append(r_text_3)
	RichTextArray.append(r_text_4)
	RichTextArray.append(r_text_5)
	
	
func _process(delta: float) -> void:
	if Autoload.dashflag == true:
		is_dash = "是"
	else:
		is_dash = "否"
	if Input.is_action_just_pressed("reset"):
		reset()
	if Input.is_action_just_pressed("时停"):
		time_debug.text = str(time_order)
	
	
	
func Thorn_appear():
	var Thorn_tween = get_tree().create_tween().set_parallel(true)
	Thorn_tween.tween_property(荆棘图,"modulate",Color(1.0, 1.0, 1.0),0.5)
	Thorn_tween.tween_property(荆棘图2,"modulate",Color(1.0, 1.0, 1.0),0.5)
	Thorn_tween.tween_property(荆棘图3,"modulate",Color(1.0, 1.0, 1.0),0.5)
	Thorn_tween.tween_property(荆棘图4,"modulate",Color(1.0, 1.0, 1.0),0.5)
	Thorn_tween.tween_property(荆棘图5,"modulate",Color(1.0, 1.0, 1.0),0.5)
	荆棘碰撞.global_position = Vector2(-139,244)
	
	
	
func _on_压力板_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and text_button_repeatable[0]:
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[0]
		text_appear(STR,0,0.15)
		await get_tree().create_timer(2.1).timeout
		压力板.queue_free() # Replace with function body.

func _on_压力板2_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and text_button_repeatable[1]:
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[1]
		text_appear(STR,1,0.15)
		压力板2.queue_free()
		pass # Replace with function body.
		
func _on_压力板3_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and Richtext_button_repeatable[0]:
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[2]
		var a=32
		var b=33
		rich_text_appear(STR,0,a,b,Color.DODGER_BLUE,"White_whale1","White_whale1",0.05)
		Richtext_button_repeatable[0] = false
		await get_tree().create_timer(2.0).timeout
		var ship_tween = create_tween().set_parallel(true)
		ship_tween.tween_property(ship,"global_position",Vector2(935,300),5.0).set_trans(Tween.TRANS_SINE)
		ship_tween.tween_property(白鲸记,"modulate",Color(1.0,1.0,1.0,1.0),3.0)
	pass # Replace with function body.
	
func _on_压力板4_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and Richtext_button_repeatable[1]:
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[3]
		var a=1
		var b=2
		rich_text_appear(STR,1,a,b,Color.DODGER_BLUE,"White_whale2","White_whale2",0.15)
		var tween4:Tween = get_tree().create_tween()
		tween4.tween_property(白鲸记,"modulate",Color(1.0,1.0,1.0,0.0),2.0)
		Richtext_button_repeatable[1] = false
		var tween_whale
	pass # Replace with function body.
	
func _on_压力板5_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and Richtext_button_repeatable[2]:
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[4]
		var a=12
		var b=12
		rich_text_appear(STR,2,a,b,Color.DODGER_BLUE,"Bold","",0.15)
		Richtext_button_repeatable[2] = false
	pass # Replace with function body.

func _on_压力板6_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		await get_tree().create_timer(1.9).timeout
		掉下书页的碰撞.global_position = Vector2(1719,439)
		var tween6:Tween = get_tree().create_tween()
		print("动画开始")
		tween6.tween_property(掉下的书页,"global_position",Vector2(1634,348),2.0).set_trans(Tween.TRANS_SINE)
		tween6.tween_property(掉下的书页,"global_position",Vector2(1849,386),2.0).set_trans(Tween.TRANS_SINE)
		tween6.tween_property(掉下的书页,"global_position",Vector2(1719,439),2.0).set_trans(Tween.TRANS_SINE)
		压力板6.queue_free()
	pass # Replace with function body.
	
func _on_压力板7_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and text_button_repeatable[2]:
		await get_tree().create_timer(1.5).timeout
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[5]
		text_appear(STR,2,0.15)
		压力板7.queue_free()
	pass # Replace with function body.
	
func _on_压力板8_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and Richtext_button_repeatable[3]:
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[6]
		var a=9
		var b=10
		rich_text_appear(STR,3,a,b,Color.FIREBRICK,"orange1","orange1",0.15)
	pass # Replace with function body.

func _on_压力板9_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and text_button_repeatable[4]:
		压力板9.queue_free()
		var tween9:Tween = get_tree().create_tween()
		tween9.tween_property(落下苦水,"global_position",Vector2(2123,840),1.0).set_trans(Tween.TRANS_QUAD)
		落下苦水碰撞.global_position = Vector2(2122,93)
		await get_tree().create_timer(0.5).timeout
		落下苦水碰撞.global_position = Vector2(2123,840)
		
		await get_tree().create_timer(1.5).timeout
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[7]
		text_appear(STR,4,0.15)
	pass # Replace with function body.

func _on_压力板10_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and Richtext_button_repeatable[4]:
		var tween10:Tween = get_tree().create_tween()
		tween10.tween_property(题目遮挡,"global_position",题目遮挡.global_position+Vector2(0,1000),2.0).set_trans(Tween.TRANS_QUAD)
		var STRarray:ContentArray = load("res://Content/Content_Don.tres")
		var STR = STRarray.Content_array[8]
		var a=21
		var b=23
		rich_text_appear(STR,4,a,b,Color.FIREBRICK,"Bold","",0.05)
	pass # Replace with function body.
	
func _on_b选项_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		var tweenB:Tween = get_tree().create_tween()
		tweenB.tween_property(斜体sprite,"modulate",Color(1.0,1.0,1.0,1.0),2.0)
		tweenB.tween_property(书,"modulate",Color(1.0,1.0,1.0,1.0),0.5)
		tweenB.tween_property(书2,"modulate",Color(1.0,1.0,1.0,1.0),0.5)
		tweenB.tween_property(书3,"modulate",Color(1.0,1.0,1.0,1.0),0.5)
		tweenB.tween_property(书4,"modulate",Color(1.0,1.0,1.0,1.0),0.5)
		斜体碰撞.global_position = Vector2(3289.649,-108.656)
		a选项.queue_free()
		b选项.queue_free()
		c选项.queue_free()
		d选项.queue_free()
		暂时阻挡.queue_free()
	pass # Replace with function body.
	
func _on_彩蛋压力板_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		var tweenC:Tween = get_tree().create_tween()
		tweenC.tween_property(沙比彩蛋,"modulate",Color(1.0,1.0,1.0,1.0),4.0)
		彩蛋压力板.queue_free()
	pass # Replace with function body.

		
func _on_下边界_body_entered(body: Node2D) -> void:
	print("进入deadzone")
	if body.is_in_group("Player"):
		trigger_game_event("Playerdead")
		await get_tree().create_timer(1.0).timeout
		reset()
	pass # Replace with function body.
	
func _on_苦水_body_entered(body: Node2D) -> void:
	print("进入deadzone")
	if body.is_in_group("Player"):
		trigger_game_event("Playerdead")
		await get_tree().create_timer(1.0).timeout
		reset()
	pass # Replace with function body.
	
func _on_落下的苦水_body_entered(body: Node2D) -> void:
	print("进入deadzone3")
	if body.is_in_group("Player"):
		var tween_water:Tween = get_tree().create_tween()
		tween_water.tween_property(黑幕,"modulate",Color(1.0,1.0,1.0,1.0),2.0)
		trigger_game_event("PlayerSpecial")
		tween_water = create_tween()
		Autoload.stage_show = true
		_on_mind_07()
		trigger_game_event("Playerslow")
	pass # Replace with function body.


func _on_场景转换点0_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and 场景转换点0:
		print("切换场景点1")
		场景转换点0 = false
		var time = 1.0
		camera_move_tween(camera_2d,Vector2(-42,-1),time)
		var tween1:Tween = get_tree().create_tween().set_parallel(true)
		tween1.tween_property(书桌,"modulate",Color(1.0,1.0,1.0,0.0),1.5)
		tween1.tween_property(黑幕,"modulate",Color(1.0,1.0,1.0,1.0),1.5)
		await tween1.finished
		Autoload.stage_show = true
		
	pass # Replace with function body.

func _on_场景转换点1_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and 场景转换点1:
		print("切换场景点2")
		场景转换点1 = false
		res.emit()
		var time = 1.5
		camera_move_tween(camera_2d,Vector2(876,-1),time)
		var tween2:Tween = get_tree().create_tween()
		tween2.tween_property(黑幕,"modulate",Color(1.0,1.0,1.0,1.0),1.5)
		await tween2.finished
		Autoload.stage_show = true
		_on_mind_06()
	pass # Replace with function body.
	
func _on_场景转换点2_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and 场景转换点2:
		print("切换场景点3")
		场景转换点2 = false
		var time = 1.5
		res.emit()
		camera_move_tween(camera_2d,Vector2(1794,-1),time)
	pass # Replace with function body.
	
func _on_场景转换点3_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and 场景转换点3:
		print("切换场景点3")
		场景转换点3 = false
		var time = 1.5
		res.emit()
		trigger_game_event("Playerreset")
		camera_move_tween(camera_2d,Vector2(2712,-1),time)
	pass # Replace with function body.
	
func _on_场景转换点4_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and 场景转换点4:
		print("切换场景点4")
		场景转换点4 = false
		var time = 2.0
		camera_move_tween(camera_2d,Vector2(3000,-1),time)
	pass # Replace with function body.
	
func _on_彩蛋_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player") and 彩蛋:
		print("彩蛋！")
		彩蛋 = false
		var time = 1.0
		camera_move_tween(camera_2d,Vector2(2412,-700),time)
	pass # Replace with function body.
	
	
func _on_checkpoint_1_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		Autoload.set_checkpoint(checkpoint_1.global_position)
	pass # Replace with function body.
	
func _on_checkpoint_2_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		Autoload.set_checkpoint(checkpoint_2.global_position)
	pass # Replace with function body.
	
func _on_checkpoint_3_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		Autoload.set_checkpoint(checkpoint_3.global_position)
	pass # Replace with function body.
	
func camera_move_tween(camera:Camera2D,target_position:Vector2,time:float):
	var tween = get_tree().create_tween()
	tween.tween_property(camera,"global_position",target_position,time).set_trans(Tween.TRANS_SINE)
	左边界.global_position+=Vector2(918,0)
	左边界域.global_position+=Vector2(918,0)



func text_appear(STR:Content,i:int,time:float):
	var content_machine:Tween
	text_button_repeatable[i] = 0
	if content_machine and content_machine.is_running():
		content_machine.kill()
	TextArray[i].text = ""
	content_machine = get_tree().create_tween()
	for contentText in STR.Content_string:
		content_machine.tween_callback(settext.bind(contentText,i)).set_delay(time)
		
func rich_text_appear(STR:Content,i:int,a:int,b:int,text_color:Color,text_effect:String,text_special_effect:String,time:float):
	var content_machine:Tween
	Richtext_button_repeatable[i] = 0
	if content_machine and content_machine.is_running():
		content_machine.kill()
	RichTextArray[i].text = ""
	
	var processed_text = preprocess_text(STR.Content_string,a,b,text_color,text_effect,text_special_effect)
	
	content_machine = get_tree().create_tween()
	for char_index in range(processed_text.size()):
		content_machine.tween_callback(rich_settext.bind(processed_text,char_index,i)).set_delay(time)
		
		
		
		
func settext(contentText,i:int):
	TextArray[i].text += contentText
	
func rich_settext(process_text:Array,char_index:int,i:int):
	if char_index > process_text.size():
		return
	var char_data = process_text[char_index]
	var current_text = RichTextArray[i].get_parsed_text()
	
	if char_data.special:
		var styled_char =apply_style(char_data)
		RichTextArray[i].append_text(styled_char)
		apply_special_effect(char_data)
	else:
		RichTextArray[i].append_text(char_data.char)
	
	
func apply_style(char_data:Dictionary)->String:
	match char_data.effect:
		"White_whale1":
			return "[wave amp=20 freq=5][b][color=#5fc1d8]" + char_data.char + "[/color][/b][/wave]"
		"White_whale2":
			return "[wave amp=20 freq=10][b][color=#5fc1d8]" + char_data.char + "[/color][/b][/wave]"
		"Bold":
			return "[b]"+char_data.char + "[/b]"
		"Bold and shake":
			return "[shake rate=20.0 level=5 connected=1][b]" + char_data.char + "[/b][/shake]"
		"orange1":
			return "[shake rate=20.0 level=5 connected=1][b][color=#ee0000]" + char_data.char + "[/color][/b][/shake]"
	return char_data.char
func apply_special_effect(char_data:Dictionary):
	match char_data.special_effect:
		"White_whale1":
			return 
		"White_whale2":
			await get_tree().create_timer(1.0).timeout
			var tween:Tween = create_tween().set_parallel(true)
			tween.tween_property(RichTextArray[1],"theme_override_colors/default_color",Color(0.373, 0.757, 0.847),0.5)
			tween.kill()
		"orange1":
			await get_tree().create_timer(2.0).timeout
			var tween:Tween = create_tween().set_parallel(true)
			tween.tween_property(RichTextArray[3],"modulate",Color(1.0,1.0,1.0,0.0),1.5)
			tween.tween_property(RichTextArray[3],"global_position",RichTextArray[3].global_position+Vector2(0,400),10.0)
			
	pass
		

func preprocess_text(text:String,a:int,b:int,text_color:Color,text_effect:String,text_special_effect:String) -> Array:
	var result = []
	for i in range(text.length()):
		var char = text[i]
		var char_data = {
			"char": char,
			"index":i,
			"special": false,
			"color":Color.BLACK,
			"effect":null,
			"special_effect":null,
		}
		if i>=a and i<=b:
			char_data.special = true
			char_data.color = text_color
			char_data.effect = text_effect
			char_data.special_effect = text_special_effect
		result.append(char_data)
	return result
	
	
func trigger_game_event(event_type:String):
	game_event.emit(event_type)
	
func _on_text_button_button_down() -> void:
	var STRarray:ContentArray = load("res://Content/Content_Don.tres")
	var STR = STRarray.Content_array[2]
	var i:int = 0
	for contentText in STR.Content_string:
		print(contentText+str(i))
		i += 1
		
func reset():
	pass # Replace with function body.

func _on_mind_00_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		control.modulate.a = 0
		label.text = "有多久没动过这些书了..."
		var tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(3.0)
		mind_00.queue_free()
	pass # Replace with function body.

func _on_area_2d_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		control.modulate.a = 0
		label.text = "这些是...小说和教材。"
		var tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(1.0)
		await tween.finished
		mind_01.queue_free()



func _on_mind_02_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		control.modulate.a = 0
		label.text = "“我将悲伤藏进心底，不以为意地继续前行”
...如今陷入泥沼，满心悲哀的我。是否还能继续前行呢。"
		var tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(3.0)
		mind_02.queue_free()


func _on_mind_03_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		control.modulate.a = 0
		label.text = "我...已经停下够久了。或许是时候如书中角色那般继续前行了。"
		var tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(1.5)
		mind_03.queue_free()


func _on_mind_04_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		control.modulate.a = 0
		label.text = "这里还有些以前留下的试卷...我应该看看才对。"
		var tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(1.5)
		mind_04.queue_free()


func _on_mind_05_body_entered(body: Node2D) -> void:
	if body.is_in_group("Player"):
		mind_05.queue_free()
		control.modulate.a = 0
		label.text = "说到底，我不去上学也是因为不想看到这些东西吧。"
		var tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(1.5)
		await tween.finished
		label.text = "........"
		tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(1.5)
		await tween.finished
		label.text = "稍微...看看吧..."
		tween = create_tween()
		tween.tween_property(control,"modulate:a",1.0,1.0)
		tween.tween_property(control,"modulate:a",0,1.0).set_delay(1.5)
		await  tween.finished
		tween = create_tween()
		tween.tween_property(黑幕,"modulate",Color(1.0,1.0,1.0,0.0),1.5)
		Autoload.stage_show = false
		Thorn_appear()
	pass # Replace with function body.
	
func _on_mind_06():
	control.modulate.a = 0
	label.text = "冒险...曾经的我喜欢这种东西吗..."
	var tween06 = create_tween()
	tween06.tween_property(control,"modulate:a",1.0,1.0)
	tween06.tween_property(control,"modulate:a",0,1.0).set_delay(1.0)
	await tween06.finished
	label.text = "...英雄踏上了旅途"
	tween06 = create_tween().set_parallel(true)
	tween06.tween_property(control,"modulate:a",1.0,1.0)
	tween06.tween_property(control,"modulate:a",0,1.0).set_delay(1.0)
	tween06.tween_property(黑幕,"modulate",Color(1.0,1.0,1.0,0.0),2.0)
	Autoload.stage_show = false
	
func _on_mind_07():
	control.modulate.a = 0
	label.text = "果然，晦涩的书本什么的还是...."
	var tween07 = create_tween()
	tween07.tween_property(control,"modulate:a",1.0,1.0)
	tween07.tween_property(control,"modulate:a",0,1.0).set_delay(1.0)
	await tween07.finished
	label.text = "........"
	tween07 = create_tween()
	tween07.tween_property(control,"modulate:a",1.0,1.0)
	tween07.tween_property(control,"modulate:a",0,1.0).set_delay(1.5)
	await tween07.finished
	label.text = "没剩多少了，接着看看吧"
	tween07 = create_tween()
	tween07.tween_property(control,"modulate:a",1.0,1.0)
	tween07.tween_property(control,"modulate:a",0,1.0).set_delay(1.5)
	await tween07.finished
	tween07 = create_tween()
	tween07.tween_property(黑幕,"modulate",Color(1.0,1.0,1.0,0.0),2.0)
	Autoload.stage_show = false
	
func _on_show_ending():
	结束.visible =true
	
	
